package com.wx.gof.pattern.structural.composite.interfacetype;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName BookCatalog
 * @Author wx
 * @Description 书目录
 * @Date 2018-12-09-20:51
 */
public class BookCatalog implements IBookCatalog {
    List<ITree> iBookCatalogList = new ArrayList<>();
    private String bookCatalogName;
    private Integer pageNumber;
    private Integer level;

    public BookCatalog(String bookCatalogName, Integer pageNumber, Integer level) {
        this.bookCatalogName = bookCatalogName;
        this.pageNumber = pageNumber;
        this.level = level;
    }

    @Override
    public String getName() {
        return this.bookCatalogName;
    }

    @Override
    public Integer getPageNumber() {
        return this.pageNumber;
    }

    @Override
    public void remove(ITree iTree) {
        this.iBookCatalogList.remove(iTree);
    }

    @Override
    public void add(ITree iTree) {
        this.iBookCatalogList.add(iTree);
    }

    @Override
    public Integer getLevel() {
        return this.level;
    }


    @Override
    public void printContent() {
        System.out.println("书目录节点名称 " + this.bookCatalogName + " 页码" + this.pageNumber + " 节点层级" + this.level);
        for (ITree iTree : this.iBookCatalogList) {
            if (this.level != null) {
                for (int i = 0; i < this.level; i++) {
                    System.out.print("  ");
                }
            }
            iTree.printContent();
        }
    }
}
